import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/*字节流响应消息*/
@WebServlet("/response")
public class ResponseDemo extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //1.创建字节输出流
        ServletOutputStream sos = resp.getOutputStream();
        //2.定义消息
        String s = "你好  我是response对象响应的数据";
        //3.通过字节流对象输出
        sos.write(s.getBytes());//默认会根据浏览器编码格式
//        sos.write(s.getBytes("utf-8"));//默认会根据浏览器编码格式
        //释放资源
        //sos.close()  response对象会自动释放资源
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
